﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace PengSW.BrowseTools
{
    public static class BrowseTools
    {
        public static string Information(this Exception ex)
        {
            return string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);
        }

        public static string GetFileName(string aFilter)
        {
            System.Windows.Forms.OpenFileDialog aDlg = new OpenFileDialog();
            aDlg.Filter = aFilter;
            if (aDlg.ShowDialog() != DialogResult.OK) return "";
            return aDlg.FileName;
        }

        public static void BrowseDbfFile(TextBox aTextBox)
        {
            string aFileName = GetFileName("股票数据 (*.dbf)|*.dbf|所有文件 (*.*)|*.*");
            if (aFileName.Trim().Length > 0) aTextBox.Text = aFileName;
        }

        public static void BrowseXmlFile(TextBox aTextBox)
        {
            string aFileName = GetFileName("Xml文件 (*.xml)|*.xml|所有文件 (*.*)|*.*");
            if (aFileName.Trim().Length > 0) aTextBox.Text = aFileName;
        }

        public static string GetPath(string aTitle)
        {
            System.Windows.Forms.FolderBrowserDialog aDlg = new FolderBrowserDialog();
            aDlg.Description = aTitle;
            if (aDlg.ShowDialog() != DialogResult.OK) return "";
            return aDlg.SelectedPath;
        }

        public static void BrowsePath(string aTitle, TextBox aTextBox)
        {
            string aPath = GetPath(aTitle);
            if (aPath.Trim().Length > 0) aTextBox.Text = aPath;
        }
    }
}
